home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / UTILFILE / UNPROPTC.LZH / PATCHER.BAS < prev    next >
BASIC Source File  |  1984-02-04  |  2KB  |  56 lines

  1. 10 'PATCHER - file patching program - PROGRAMMERS JOURNAL Vol 1, No 6, Pg. 21
  2. 20 'Copyright 1983 - Data Base Decisions, Atlanta, GA
  3. 30 'This program is used to patch other programs or files. It requires
  4. 40 'a data file containing the patches. The first three items in the
  5. 50 'patch file are the name of the file to be patched, a check sum, and
  6. 60 'comments. For each byte to be patched, there is one record containing
  7. 70 'the offset of the byte to be patched, the old value of the byte,
  8. 80 'and the new (patch) value.
  9. 90 'Patches are generated using program  GENPATCH.BAS
  10. 100 'Note: If the offset is greater than 32,767, BASIC 2.00 must be used.
  11. 110 CLS
  12. 120 DEFINT A-Z
  13. 130 CLEAR
  14. 140 ON ERROR GOTO 500
  15. 150 CLOSE
  16. 160 PRINT : INPUT "Name of file containing patches";PAT$
  17. 170 IF PAT$="" THEN  END
  18. 180 OPEN "i",#1,PAT$
  19. 190 INPUT #1,FIL$,CKSUM!,COMMENT$
  20. 200 OPEN "i",#2,FIL$    'is it there
  21. 210 PRINT "Patching: " FIL$
  22. 220 PRINT "Comments: " COMMENT$
  23. 230 CLOSE 2
  24. 240 OPEN "r",#2,FIL$,1  'reopen as random file
  25. 250 FIELD 2,1 AS R$
  26. 260 FILE.LEN = LOF(2)
  27. 270 IF EOF(1) THEN 450
  28. 280 INPUT# 1,BYTE!,OLDVAL,NEWVAL    'get patch
  29. 290 NEWSUM!=(NEWSUM!+BYTE!+OLDVAL!+NEWVAL!)
  30. 300 PRINT BYTE!,OLDVAL,NEWVAL, "Checksum " NEWSUM!
  31. 310 IF NEWSUM! > 32767 THEN NEWSUM!=NEWSUM!-32767: GOTO 310
  32. 320 IF BYTE! > FILE.LEN THEN PRINT "Byte " BYTE! " is beyond end of file": GOTO 400
  33. 330 GET 2,BYTE!
  34. 340 R=ASC(R$)
  35. 350 IF R <> OLDVAL THEN PRINT "Old value for byte " BYTE! " is " R " not " OLDVAL: GOTO 400
  36. 360 LSET R$=CHR$(NEWVAL)
  37. 370 PUT 2,BYTE!
  38. 380 APPLIED=APPLIED+1
  39. 390 GOTO 270
  40. 400 REM *** invalid condition ***
  41. 410 BEEP:INPUT "Continue (y/n)";ANS$
  42. 420 IF ANS$="Y" OR ANS$="y" THEN 390
  43. 430 IF ANS$="N" OR ANS$="n" THEN 450
  44. 440 GOTO 400
  45. 450 REM *** wrap it up ***
  46. 460 IF CKSUM!=NEWSUM! THEN PRINT "Checksums match" ELSE PRINT "Checksums do not match -- input value is"CKSUM! " and calculated value is "NEWSUM!: BEEP
  47. 470 PRINT "Patches applied: " APPLIED
  48. 480 CLOSE
  49. 490 END
  50. 500 REM *** error handler ***
  51. 510 UNABLE$="Unable to "
  52. 520 IF ERL=180 OR ERL=280 THEN PRINT UNABLE$ "read " PAT$
  53. 530 IF ERL=200 OR ERL=240 OR ERL=330 THEN PRINT UNABLE$ "read " FIL$
  54. 540 IF ERL=370 THEN PRINT UNABLE$ "write " FIL$
  55. 550 RESUME 120
  56.